<?php

/**
 * MVM_MALL 网上商店系统  公告牌管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-15 $
 * $Id: board.inc.php  www.mvmmall.com$
 * ---------------------------------------------
*/
if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if ($action=='list') {
    $result    = $db->query("SELECT board_name_code,uid,board_title FROM `{$tablepre}badmin_table`");
    while ($rt = $db->fetch_array($result)) {
        $rt['edit']    = "admincp.php?module=$module&action=edit&uid=$rt[uid]";
        $rt['del']     = "admincp.php?module=$module&action=del&uid=$rt[uid]";
        $rt['cat']     = "admincp.php?module=board_category&action=list&uid=$rt[uid]";
        $board_rt[]    = $rt;
    }
    require_once template('board');
    footer();
} elseif ($action=='add'  && $setp==1 && $_POST){
    !$board_code          && admin_msg('existence_code');
    !isalnum($board_code) && admin_msg('alnum_code');
    $board_code           = dhtmlchars($board_code);
    $co_result            = $db->counter("{$tablepre}badmin_table","board_name_code = '$board_code'","*");
    $co_result > 0        &&  admin_msg('use_code');
    $query = "INSERT INTO `{$tablepre}badmin_table` SET
                   board_name_code     = '$board_code',
                   board_gohome_target = '_blank',
                   board_skin          = 'default',
                   board_title         = '$board_name',
				   approval_date       = '$m_now_time',
                   register_date       = '$m_now_time'";
    $db->query($query);
    admin_msg('success','admincp.php?module=board&action=list');
}elseif ($action=='edit' && is_numeric($uid)) {
    if($setp==1&&$_POST){
        !$board_code          && admin_msg('existence_code');
        !isalnum($board_code) && admin_msg('alnum_code');
        $board_code           = dhtmlchars($board_code);
        $co_result = $db->counter("{$tablepre}badmin_table","board_name_code = '$board_code' and uid <> $uid","*");
        $co_result > 0        &&  admin_msg('use_code');
        unset($row);
        $row = array(
        'board_name_code'      => $board_code,
        'board_gohome'         => $board_gohome,
        'board_gohome_target'  => $board_gohome_target,
        'board_skin'           => $board_skin,
        'table_width'          => $table_width,
        'str_length'           => $str_length,
        'list_num'             => $list_num,
        'page_num'             => $page_num,
        'comment_num'          => $comment_num,
        'board_title'          => $board_title,
        'board_title_image'    => $board_title_image,
        'desc_text'            => $desc_text,
        'formula'              => $formula,
        'use_list'             => $use_list,
        'write_code'           => $write_code,
        'reply_code'           => $reply_code,
        'use_category'         => $use_category,
        'use_html'             => $use_html,
        'use_filter'           => $use_filter,
        'use_autolink'         => $use_autolink,
        'use_comment'          => $use_comment,
        'use_secret'           => $use_secret,
        'use_search'           => $use_search,
        'use_viewip'           => $use_viewip,
        'use_spam'             => $use_spam,
        'use_print'            => $use_print,
        'filter_text'          => $filter_text,
        'remote_connect'       => $remote_connect,
        'ip_select'            => $ip_select,
        'ip_close'             => $ip_close,
        'ip_connect'           => $ip_connect,
        'name_close'           => $name_close,
        'use_mailer'           => $use_mailer,
        'use_admin_remail'     => $use_admin_remail,
        'use_white_remail'     => $use_white_remail,
        'class_list'           => $class_list,
        'class_view'           => $class_view,
        'class_write'          => $class_write,
        'class_comment'        => $class_comment,
        'class_reply'          => $class_reply,
        'class_modify'         => $class_modify,
        'class_delete'         => $class_delete,
        'class_notice'         => $class_notice,
        'class_secret'         => $class_secret,
        'class_html'           => $class_html,
        'class_download'       => $class_download,
        'class_print'          => $class_print,
        'class_approval'       => $class_approval,
        'approval_date'        => $approval_date
        );
        $db->update("{$tablepre}badmin_table",$row,"uid='$uid'");
        admin_msg('success','admincp.php?module=board&action=list');
    } else {
        $rt = $db->get_one("SELECT * FROM `{$tablepre}badmin_table` WHERE uid = '$uid'");
        @extract($rt,EXTR_OVERWRITE);
        //下拉菜单
        $html_menu   = drop_menu($cache->get_cache('grade'),'class_html',$class_html);
        $secret_menu = drop_menu($cache->get_cache('grade'),'class_secret',$class_secret);
        $delete_menu = drop_menu($cache->get_cache('grade'),'class_delete',$class_delete);
        $modify_menu = drop_menu($cache->get_cache('grade'),'class_modify',$class_modify);
        $notice_menu = drop_menu($cache->get_cache('grade'),'class_notice',$class_notice);
        $reply_menu  = drop_menu($cache->get_cache('grade'),'class_reply',$class_reply);
        $comme_menu  = drop_menu($cache->get_cache('grade'),'class_comment',$class_comment);
        $write_menu  = drop_menu($cache->get_cache('grade'),'class_write',$class_write);
        $view_menu   = drop_menu($cache->get_cache('grade'),'class_view',$class_view);
        $list_menu   = drop_menu($cache->get_cache('grade'),'class_list',$class_list);
        //IP 限制选择
        switch ($ip_select){
            case '0': { $ip_reschk   = 'checked'; break; }
            case '1': { $ip_shiechk  ='checked'; break; }
            default:  { $ip_allowchk = 'checked';}
        }
        //邮件发送
        $remote_connect == 0  ?   $conn_chk = 'checked': $remote_chk = 'checked' ;
        //远程连接
        $use_admin_remail == 1    && $use_chk      = 'checked';
        //间隔时间限制
        $use_spam == 1            && $spam_chk     = 'checked';
        //IP显示
        $use_viewip == 1          && $viewip_chk   = 'checked';
        //搜索
        $use_search == 1          && $search_chk   = 'checked';
        //悄悄话
        $use_secret == 1          && $secret_chk   = 'checked';
        //简单回复
        $use_comment == 1         && $comment_chk  = 'checked';
        //自动链接
        $use_autolink == 1        && $autolink_chk = 'checked';
        //HTML 使用式
        $use_html == 1            && $html_chk     = 'checked';
        //回复文章验证码
        $reply_code == 1          && $reply_chk    = 'checked';
        //发表文章验证码
        $write_code == 1          && $write_chk    = 'checked';
        //分类使用
        $use_category == 1        && $category_chk = 'checked';
        //脏话过滤
        $use_filter ==1           && $filter_chk   = 'checked';
        //文章主题输出
        $use_list ==1             && $title_chk    = 'checked';
        require_once template('board_add');
        footer();
    }
} elseif ($action=='del' && is_numeric($uid)){
    $rt_board = $db->get_one("SELECT uid,board_name_code FROM `{$tablepre}badmin_table` WHERE uid = '$uid'");
    $db->query("DELETE FROM `{$tablepre}bcategory` WHERE ps_name = '$rt_board[board_name_code]'");//删除小分类表
    //删除回复表
    $result=$db->query("SELECT uid,ps_name FROM `{$tablepre}bmain` WHERE ps_name = '$rt_board[board_name_code]'");
    while ($rt=$db->fetch_array($result)){
        $fid.=','.$rt['uid'];
    }
    $fid = substr($fid, 1);
    $fid &&  $db->query("DELETE FROM `{$tablepre}bcomment` WHERE fid IN($fid)");
    //end
    $db->query("DELETE FROM `{$tablepre}bmain` WHERE ps_name = '$rt_board[board_name_code]'");//删除文章表
    $db->query("DELETE FROM `{$tablepre}badmin_table` WHERE uid = '$uid'");//删除公告牌
} else {
    admin_msg('pass_worng');
}
